package com.xxx.system.service.impl;


import com.github.pagehelper.PageHelper;
import com.xxx.system.domain.Permission;
import com.xxx.system.mapper.PermissionMapper;
import com.xxx.system.query.PermissionQuery;
import com.xxx.system.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
//查询事务控制方式：设置只读 支持当前事务，如果没有当前事务，就以非事务方法执行。
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    @Transactional
    public void addPermission(Permission permission) {
        permissionMapper.addPermission(permission);
    }

    @Override
    @Transactional
    public void updatePermission(Permission permission) {
        permissionMapper.updatePermission(permission);
    }

    @Override
    @Transactional
    public void deteleById(Long id) {
        permissionMapper.deteleById(id);
    }

    @Override
    public Permission findOne(Long id) {
        return permissionMapper.findOne(id);
    }

    @Override
    public List<Permission> findAll() {
        return permissionMapper.findAll();
    }

    @Override
    public List<Permission> queryPage(PermissionQuery permissionQuery) {
        //开始设置分页信息
        //干了三件事情：
        //1.查询总条数 2.根据驱动名称自动添加分页 3.分页查询返回结果
        PageHelper.startPage(permissionQuery.getCurrentPage(), permissionQuery.getPageSize());
        //直接高级查询，自动实现分页
        return permissionMapper.queryPage(permissionQuery);
    }

    @Override
    @Transactional
    public void deletePermissionByIds(Long[] ids) {
        permissionMapper.deletePermissionByIds(ids);
    }
}
